<?php

class MiniCMS_ControllerPlugin extends Zend_Controller_Plugin_Abstract
{
	public function preDispatch(Zend_Controller_Request_Abstract $request)
    {

    	/* takes the page title from config file */
    	$path = explode("/", $this->getRequest()->getRequestUri());
    	$pagesTitle = Zend_Registry::get("config")->page->toArray();
    	$title = Zend_Registry::get("config")->page->home->title;
    	foreach ( $pagesTitle as $key => $page ) {
	    	if ( $key == $path[1] ) {
	    		$title = $pagesTitle[$path[1]]["title"];
	    	}
    	}

    	Zend_Registry::get("view")->pageTitle = $title;

    	$this->getResponse()->appendBody(Zend_Registry::get("view")->render("header.phtml"));

		if ($_SESSION["isLoggedIn"] == "true"){
			$this->getResponse()->appendBody(Zend_Registry::get("view")->render("menuLoggedIn.phtml"));
    		$this->getResponse()->appendBody(Zend_Registry::get("view")->render("sideLeftLoggedIn.phtml"));
		}else {
    		$this->getResponse()->appendBody(Zend_Registry::get("view")->render("menuNoLogin.phtml"));
    		$this->getResponse()->appendBody(Zend_Registry::get("view")->render("sideLeftNoLogin.phtml"));
		}

    }

	public function postDispatch(Zend_Controller_Request_Abstract $request)
    {
        $this->getResponse()
             ->appendBody(Zend_Registry::get("view")->render("footer.phtml"));
    }
}
?>